/*
 * Copyright 2025 arisgo@163.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.arisgo.cloud.attendance.clazz.api;

import com.arisgo.cloud.attendance.clazz.service.GroupStaffService;
import com.arisgo.cloud.attendance.clazz.vo.GroupStaffVo;
import com.arisgo.cloud.attendance.clazz.vo.StaffVo;
import com.arisgo.cloud.common.Pagination;
import com.arisgo.cloud.common.Result;
import com.arisgo.cloud.web.param.Paging;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 排班组员工 Api
 *
 * @author Coulson
 * @since 2025-03-26
 */
@RestController
@AllArgsConstructor
@Tag(name = "排班组员工 API", description = "排班组员工CRUD操作")
public class GroupStaffApi {

    private final GroupStaffService groupStaffService;

    /**
     * 分页查询排班组员工
     */
    @PostMapping(value = "/group/{groupId}/staff/page")
    @Operation(summary = "分页查询")
    public Result<Pagination<StaffVo>> page(@PathVariable(value = "groupId") Long groupId,
                                            @RequestBody Paging paging) {
        return Result.success(groupStaffService.findByGroupId(groupId, paging));
    }

    /**
     * 保存排班组员工
     */
    @PostMapping(value = "/group/staff")
    @Operation(summary = "新增数据")
    public Result<GroupStaffVo> save(@RequestBody GroupStaffVo vo) {
        return Result.success(groupStaffService.save(vo));
    }

    /**
     * 物理删除排班组员工
     */
    @DeleteMapping(value = "/group/staff/remove/{id}")
    @Operation(summary = "单个物理删除")
    public Result<Boolean> remove(@PathVariable(value = "id") Long id) {
        return Result.success(groupStaffService.remove(id));
    }

    /**
     * 物理删除排班组员工
     */
    @DeleteMapping(value = "/group/{groupId}/staff")
    @Operation(summary = "批量物理删除")
    public Result<Boolean> remove(@PathVariable(value = "groupId") Long groupId,
                                  @RequestBody List<Long> ids) {
        return Result.success(groupStaffService.removeByGroupId(groupId, ids));
    }


}
